home *** CD-ROM | disk | FTP | other *** search
- /*
- CDTime - An XFCN to report a variety of relevant times
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDTime.c
- link -sn Main=CDTime -sn STDIO=CDTime ∂
- -sn INTENV=CDTime -rt XFCN=42 ∂
- -m CDTime CDTime.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDTime
- *
- * Purpose: return several different times relevant to this disc
- *
- * Returns: a comma separated list, or an error
- * if it's a negative number, it's an error
- * if we return nothing, wrong number of parameters
- * were specified.
- *
- * The list contains 15 items:
- * Items 1, 2, 3 are elapsed time, current track
- * Items 4, 5, 6 are remaining time, current track
- * Items 7, 8, 9 are elapsed time on disc
- * Items 10, 11, 12 are remaining time on disc
- * Items 13, 14, 15 are total run time on disc
- * all times are absolute minute, second and block.
- *
- * Side Effects:
- *
- * Description: We need no parameter:
- * Get the ioRefNum that we got from previously calling
- * CDOpen() by accessing a famous global
- *
- ************************************************************************/
- pascal void
- CDTime(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str255 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- long trackNo;
- long currentMinute, currentSecond, currentBlock; /* current spot */
- long startMinute, startSecond, startBlock; /* start of track */
- long elapsedMinute, elapsedSecond, elapsedBlock; /* used up */
- long remainMinute, remainSecond, remainBlock; /* remaining */
- long remainDiscMinute, remainDiscSecond, remainDiscBlock;
- long totalDiscMinute, totalDiscSecond, totalDiscBlock;
- long args[15];
-
- /* Must be no parameter */
- if ((paramPtr->paramCount) != 0)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- result = ReadQ(ioRefNum, &trackNo, ¤tMinute, ¤tSecond, ¤tBlock);
-
- if (result == noErr)
- result = TrackStart(ioRefNum, trackNo+1, &remainMinute, &remainSecond, &remainBlock);
-
- if (result != noErr) /* we specified an invalid track. Use disc time */
- result = DiscTime(ioRefNum, &remainMinute, &remainSecond, &remainBlock);
-
- if (result == noErr)
- {
- TimeDiff(&remainMinute, &remainSecond, &remainBlock,
- remainMinute, remainSecond, remainBlock,
- currentMinute, currentSecond, currentBlock);
- }
-
- if (result == noErr)
- result = TrackStart(ioRefNum, trackNo, &startMinute, &startSecond, &startBlock);
-
- if (result == noErr)
- {
- TimeDiff(&elapsedMinute, &elapsedSecond, &elapsedBlock,
- currentMinute, currentSecond, currentBlock,
- startMinute, startSecond, startBlock);
- }
-
- if (result == noErr)
- result = DiscTime(ioRefNum, &totalDiscMinute, &totalDiscSecond, &totalDiscBlock);
-
- if (result == noErr)
- {
- TimeDiff(&remainDiscMinute, &remainDiscSecond, &remainDiscBlock,
- totalDiscMinute, totalDiscSecond, totalDiscBlock,
- currentMinute, currentSecond, currentBlock);
- }
-
- if (result == noErr)
- {
- TimeDiff(&totalDiscMinute, &totalDiscSecond, &totalDiscBlock,
- totalDiscMinute, totalDiscSecond, totalDiscBlock,
- 0, 0, 1); /* report time as 1 block less than actual */
- }
-
-
- args[0] = elapsedMinute;
- args[1] = elapsedSecond;
- args[2] = elapsedBlock;
- args[3] = remainMinute;
- args[4] = remainSecond;
- args[5] = remainBlock;
- args[6] = currentMinute;
- args[7] = currentSecond;
- args[8] = currentBlock;
- args[9] = remainDiscMinute;
- args[10] = remainDiscSecond;
- args[11] = remainDiscBlock;
- args[12] = totalDiscMinute;
- args[13] = totalDiscSecond;
- args[14] = totalDiscBlock;
-
- FormatString(&returnString, args, 15);
-
- if (result == noErr)
- {
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- else
- {
- /* We got an error. Convert result to string & return it as error */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- }
-
-
-
-
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-